/*
 * @Author: xiweidong 1324156920@qq.com
 * @Date: 2024-08-24 09:43:11
 * @LastEditors: xiweidong 1324156920@qq.com
 * @LastEditTime: 2024-08-30 15:00:24
 * @FilePath: \cesium-1.87-demo\graphicStyle\initViewer.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import * as Cesium from 'cesium';

Cesium.Ion.defaultAccessToken =
  "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkY2VlZjI5MC0xMDZhLTRhMGQtOGM3NS0yZTczYWYxNzk0N2UiLCJpZCI6NTIzNzQsImlhdCI6MTYxODU2NTAwMn0.hSaADqKUhy3azmrauo9-9OHEEhg2Cplm4x8aFzEpO4Q";
Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(
  73.55,
  3.85,
  135.083,
  53.55
);
//初始化三维场景
// console.log(Cesium.TerrainProvider.getRegularGridIndices(16, 16));
// eslint-disable-next-line es/no-classes
function initViewer(_viewerContainer, _options = {}) {
  const viewer = new Cesium.Viewer(_viewerContainer, {
    animation: false,
    baseLayerPicker: false,
    fullscreenButton: false,
    geocoder: false,
    homeButton: false,
    infoBox: false,
    sceneModePicker: false,
    selectionIndicator: false,
    timeline: false,
    navigationHelpButton: false,
    scene3DOnly: true,
    clockViewModel: new Cesium.ClockViewModel(new Cesium.Clock()),
    // imageryProvider:
    //new Cesium.UrlTemplateImageryProvider({
      //   url:
      //     ' https://t{s}.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=' +
      //     'aef1277d283beb91a608f2971d735fb2',
      //   subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'],
      //   tilingScheme: new Cesium.WebMercatorTilingScheme(),
      //   maximumLevel: 18,
      // }),
      // new Cesium.SingleTileImageryProvider({
      //   url: "./images/globe.png",
      // }),
    //Cesium.createWorldTerrain(),
    terrainProvider:
      new Cesium.EllipsoidTerrainProvider({
        ellipsoid: Cesium.Ellipsoid.WGS84,
      }),
      // new EllipsoidTerrainProvider(),
      // new Cesium.TerrainProvider({
      //   url: "http://localhost:12020/sx_terrain/", // Cesium.IonResource.fromAssetId(3956),
      //   requestVertexNormals: true,
      // }),
    skyBox: false,
    fullscreenElement: document.body,
    useDefaultRenderLoop: true,
    targetFrameRate: undefined,
    showRenderLoopErrors: true,
    automaticallyTrackDataSourceClocks: true,
    contextOptions: undefined,
    mapProjection: new Cesium.WebMercatorProjection(Cesium.Ellipsoid.WGS84),
    dataSources: new Cesium.DataSourceCollection(),
    skyAtmosphere: false,
    shouldAnimate: true,
  });
  // viewer.scene.globe.baseColor = Cesium.Color.BLACK;
  // _options._hideGlobe
  //     ? ((viewer.scene.globe.translucency.enabled = true), //此属性设置为true-下面的设置才能生效
  //         (viewer.scene.globe.baseColor = Cesium.Color.TRANSPARENT),
  //         (viewer.scene.globe.undergroundColor = Cesium.Color.TRANSPARENT))
  //     : ''
  // _options._defineBgImage
  //     ? (viewer.scene.backgroundColor = Cesium.Color.TRANSPARENT)
  //     : ''
  // viewer.scene.backgroundColor = Cesium.Color.WHITE.withAlpha(0.5);//同czm_backgroundColor
  if (Cesium.FeatureDetection.supportsImageRenderingPixelated()) {
    const pixelRatio = window.devicePixelRatio;
    viewer.resolutionScale = pixelRatio; //window.devicePixelRatio
  }
  viewer.scene.fxaa = true;
  viewer.scene.postProcessStages.fxaa.enabled = true;
  viewer.scene.globe.baseColor = new Cesium.Color(0, 0, 0, 1);
  viewer._cesiumWidget._creditContainer.style.display = "none";
  !!_options.removeAll ? viewer.scene.imageryLayers.removeAll(true) : "";
  viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(
    Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK
  );
  viewer.scene.screenSpaceCameraController.zoomEventTypes = [
    Cesium.CameraEventType.WHEEL,
    Cesium.CameraEventType.PINCH,
  ];
  viewer.scene.screenSpaceCameraController.tiltEventTypes = [
    Cesium.CameraEventType.PINCH,
    Cesium.CameraEventType.RIGHT_DRAG,
  ];
  // viewer.scene.globe.depthTestAgainstTerrain = true //设置为true,可以避免地底下的面显示在地上
  return viewer;
}

export default initViewer;
